class User():
    id = 1
    name = 'disen'
    money = 20000

def save(entity):
    # 读取对象的普通属性
    # 1.
    print([attr for attr in dir(entity) if not attr.startswith('__')])
    # 2.
    print(entity.__dict__)
    # 3.
    print({attr:getattr(entity, attr) for attr in dir(entity) if not attr.startswith('__')})

    sql = "insert into %s(%s) values(%s)"
    # 获取表名 user
    table = entity.__class__.__name__.lower()
    colnames = ','.join([col for col in entity.__dict__])
    colplaceholders = ','.join(["%%(%s)s" % col for col in entity.__dict__])

    sql = sql % (table,colnames,colplaceholders)
    print(sql)

if __name__ == '__main__':
    u1 = User()
    u1.id = 1000
    u1.name = 'jack'
    u1.money = 30000

    u2 = User()
    u2.id = 2000
    u2.name = '张三'
    u2.money = 40000

    save(u1)
    save(u2)